package ui;

import org.newdawn.slick.AngelCodeFont;
import org.newdawn.slick.Font;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.gui.GUIContext;
import org.newdawn.slick.gui.TextField;

import framework.C;

public class Slider extends TextField {
	
	private String[] values;
	
	private int index;
	
	private static final int SIZE = 20;
	
	AngelCodeFont font;

	public String[] getValues() {
		return values;
	}

	public void setValues(String[] values) {
		this.values = values;
	}

	public Slider(GUIContext container, Font font, int x, int y, int width,
			int height) {
		super(container, font, x, y, width, height);
		index = 0;
		values = new String[1];
		values[0] = "0";
		try {
			this.font = new AngelCodeFont(C.FONTS_FOLDER + "menu_hover.fnt", C.FONTS_FOLDER + "menu_hover.png");
		} catch (SlickException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public void render(GUIContext container, Graphics g) {
		g.setFont(C.Font.REGULAR_FONT);
		g.drawString("-" + values[index] + "+", getX(), getY());
	}

	@Override
	public void mousePressed(int button, int x, int y) {
		if (x >= getX() && x <= getX() + SIZE && y >= getY() && y <= getY() + SIZE) {
			index = index - 1 < 0 ? values.length - 1 : index -1;
		} else if(x >= getX() + 50 && x <= getX() + 50 + SIZE && y >= getY() && y <= getY() + SIZE) {
			index = index + 1 < values.length ? index + 1 : 0;
		}
	}
}
